import { Staff } from "@/global/global";
import { InjectionKey } from "vue";
import { createStore, Store } from "vuex";
import createVuexAlong from 'vuex-along'


interface State {
  staff: Staff | undefined;
  token: string | undefined;
}

const userStateKey: InjectionKey<Store<State>> = Symbol();
const userState = createStore<State>({
  state() {
    return {
      staff: undefined,
      token: undefined,
    };
  },
  mutations: {
    setStaff(state, staff) {
      state.staff = staff;
    },
    setToken(state, token) {
      state.token = token;
    }
  },
  // 用于持久化vuex数据的插件
  plugins: [ createVuexAlong() ]
});
export { userState, userStateKey };
